<?php


namespace App\Services;


use App\Tools\JsonTools;

class HouseWayPayHouse implements HouseWay
{
    protected $data;
    protected  $limit;
    protected $offset;
    protected $houseWay;
    public function __construct($data,$limit,$offset,$houseWay)
    {
        $this->houseWay=$houseWay;
        $this->data=$data;
        $this->limit=$limit;
        $this->offset=$offset;
    }

    function houseWay()
    {
        if(!empty($this->data['search'])){
            $res=ElasticSearchService::getInstance();
            $houseInfo=$res->searchDocument('house_list',$this->limit,$this->offset,'house_name',$this->data['search']);
            return $houseInfo;
        }
        $where = [];
        $city=$this->data['city'];
        if ($city) {
            $where[] = [
                'house_city', 'like', "%$city%"
            ];
        }
        $areaInfo=$this->data['areaInfo'];
        if ($areaInfo) {
            $where[] = [
                'house_area', '=', "$areaInfo"
            ];
        }
        $houseTypeId=$this->data['houseTypeId'];
        if ($houseTypeId) {
            $where[] = [
                'house_type', '=', "$houseTypeId"
            ];
        }
        $houseMoldingId=$this->data['houseMoldingId'];
        if ($houseMoldingId) {
            $where[] = [
                'house_moldings', '=', "$houseMoldingId"
            ];
        }

        $houseInfo = HouseTypeInfoServer::houseInfo($this->offset,$this->limit,$where,$this->houseWay);
        if ($houseInfo) {
            return $houseInfo;
        } else {
            return false;
        }

    }

}
